

const util = require('../../utils/util.js');

Page({
  data: {
    remenImageWidth: 160,
    topSwiperHeight: 150,
    bottomSwiperHeight: 150,
    indicatorDots: true,
    autoplay: true,
    interval: 3000,
    duration: 2000,
    searchValue: "",
    list1: [],
    list2: [],
    list3Url: '',
    list5Url: '',
    girdList: [
      {
        url: '/images/home/gird9/g1.png',
        name: '居家育儿',
        path: '0',
        id: '9bc4785d7547016e79ee3d917eccd578'
      },
      {
        url: '/images/home/gird9/g2.png',
        name: '家务料理',
        path: '1',
        id: 'c9dd76b3ef0c21fd5f55c23fb27330ef'
      },
      {
        url: '/images/home/gird9/g3.png',
        name: '居家养老',
        path: '2',
        id: 'cc0aef8db8eea1afa7d63f5aa6254ad2'
      },
      {
        url: '/images/home/gird9/g4.png',
        name: '母婴护理',
        path: '3',
        id: '97371c2ce41f257ada717c0f15566817'
      },
      {
        url: '/images/home/gird9/g5.png',
        name: '居家保洁',
        path: '4',
        id: 'e48dbadb859c3184f56cd550a85d7265'
      },
      {
        url: '/images/home/gird9/g6.png',
        name: '整理收纳',
        path: '5',
        id: '3c63d1026457b886b2208cf506a21df0'
      },
      {
        url: '/images/home/gird9/g7.png',
        name: '专属管家',
        path: '6',
        id: '79e8c60dcad6b82d5bb1965245f42983'
      },
      {
        url: '/images/home/gird9/g8.png',
        name: '更多服务',
        path: '0',
        id: '666c5bd20b017090fd6cd2670a0af10d'
      },
    ],
    logs: []
  },
  doItem1(e) {
    const data = e.currentTarget.dataset;
    wx.setStorageSync('hometofenlei', data.item);
    console.log(data)
    wx.switchTabgo({ 'url': '/pages/fenlei/index' });
  },
  doMore2() {
    wx.setStorageSync('hometofenlei', '9bc4785d7547016e79ee3d917eccd578');
    wx.switchTabgo({ 'url': '/pages/fenlei/index' });
  },
  doItem2(e) {
    const data = e.currentTarget.dataset;
    wx.setStorageSync('hometofenlei', data.item);
    wx.switchTabgo({ 'url': '/pages/fenlei/index' });
  },
  doItem3(e) {
    const data = e.currentTarget.dataset;
    console.log(data.item)
    wx.setStorageSync('fenlei_yuyue', { id: data.item });
    wx.navigateTo({ url: '/page2/yuyue/index?id=' + data.item });
  },
  doItemPZ() {
    console.log('/pages2/guanjiajiawu/index')
    wx.navigateGo({ url: '/page2/peizhenfuwu/index' });
  },
  doItem6() {
    wx.switchTabgo({ 'url': '/pages/zhenxuan/index' });
  },
  doInit(type) {
    const _this = this;
    util.https('home/homeResourceSearch', {
      "usages": type
    }, (res) => {
      console.log('success')
      console.log(res)
      if (type === 1) {
        this.setData({
          list1: res.resourceUrl.split(',')
        })
        if (res.clearLoaction) {
          wx.clearStorageSync();
        }
        // console.log(_this.data.list1)
        // const image1 = _this.data.list1[0];
        // console.log(image1)
        // wx.getImageInfo({
        //   src: image1,
        //   success: function (res) {
        //     console.log('图片高度:', res.height);
        //     _this.setData({
        //       topSwiperHeight: res.height
        //     })
        //   },
        //   fail: function (err) {
        //     console.error('获取图片信息失败:', err);
        //   }
        // });
        // this.setData({
        //   topSwiperHeight: height1,
        // })
      } else if (type === 2) {
        this.setData({
          list2: res.resourceUrl.split(',')
        })
      } else if (type === 3) {
        this.setData({
          list5Url: res.resourceUrl
        })
      }

    }, (res) => {
      wx.showModal({
        title: '温馨提示',
        content: res.errorMsg,
        confirmColor: '#F08302',
        showCancel: false,
        success(res) {
        }
      })
    })
  },
  onShow() {
    this.doInit(1);
    this.doInit(2);
    this.doInit(3);
    if (typeof this.getTabBar === 'function' &&
      this.getTabBar()) {
      this.getTabBar().setData({
        selected: 2
      })
    }
  },
  onLoad() {
    const systemInfo = wx.getSystemInfoSync();
    console.log(systemInfo)
    let height1 = (systemInfo.windowWidth - 375) * 0.4 + 120, height2 = (systemInfo.windowWidth - 375) * 0.4 + 120;
    this.setData({
      topSwiperHeight: height1,
      bottomSwiperHeight: height2,
      remenImageWidth: systemInfo.windowWidth * 0.427
    })
    // this.setData({
    //   logs: (wx.getStorageSync('logs') || []).map(log => {
    //     return {
    //       date: util.formatTime(new Date(log)),
    //       timeStamp: log
    //     }
    //   })
    // })
  },
  inputOnConfirm() {
    console.log(this.data.searchValue);
    wx.setStorageSync('fenleiSearchInputType', '1');
    wx.setStorageSync('fenleiSearchInput', this.data.searchValue);
    wx.switchTabgo({ 'url': '/pages/fenlei/index' });
  },
  onShareAppMessage() {

  },
})
